import 'package:pigeon/pigeon.dart';

/**
 *
    flutter pub run pigeon --input pigeons/all_types_pigeon.dart --dart_out lib/all_types_pigeon.dart --objc_header_out ios/Classes/AllTypesPigeon.h --objc_source_out ios/Classes/AllTypesPigeon.m --java_out android/src/main/java/com/example/flutter_pigeon_plugin/AllTypesPigeon.java --java_package "com.example.flutter_pigeon_plugin"

 */
class Everything {
  bool? aBool;
  int? anInt;
  double? aDouble;
  String? aString;
  Uint8List? aByteArray;
  Int32List? a4ByteArray;
  Int64List? a8ByteArray;
  Float64List? aFloatArray;

  // ignore: always_specify_types
  List? aList;

  // ignore: always_specify_types
  Map? aMap;
  List<List<bool?>?>? nestedList;
  Map<String?, String?>? mapWithAnnotations;
}

//{
//     "id": "null",
//     "linkType": "ForceAliLinkTypeNone",
//     "productKey": "a1noYnuhf7a",
//     "deviceName": "null",
//     "productId": "11311349",
//     "devType": "ble_subtype_12",
//     "remainTime": "null",
//     "mac": "84:9D:C2:20:C4:3C",
//     "addDeviceFrom": "null",
//     "regProductKey": "null",
//     "regDeviceName": "null",
//     "protocolVersion": "1.0",
//     "service": "null",
//     "fwVersion": "null",
//     "token": "null",
//     "tag": "1651930754309",
//     "regionInfo": "null",
//     "extraDeviceInfo": "null",
//     "bindResultInfo": "null",
//     "iotId": "null",
//     "regIotId": "null",
//     "deviceId": "null"
// }

///设备信息，目前这几个有值
class DeviceInfo {
  String? linkType;
  String? productKey;
  String? productId;
  String? devType;
  String? mac;
  String? protocolVersion;
  String? deviceName;
  String? token;
}

///{productKey:a1T5Pde7XEc
///deviceName:849dc220c43c
///token:46B1C3EA38BBD71CD18C66B78EE83874
///bindResult:-1
///iotId:null
///pageRouterUrl:null
///categoryKey:null
///errorCode:null
///subErrorCode:null
///localizedMsg:null}
class GetTokenResult {
  String? productKey;
  String? deviceName;
  String? token;
}

class DCErrorCode {
  String? code;
  String? subcode;
  String? codeName;
  String? msg;
}

class OtaNewVersionInfo {
  String? moduleName;
  String? currentVersion;
  String? status;
  String? firmwareVersion;
  String? size;
  String? sign;
  String? signMethod;
  String? url;
  String? details;
  String? otaType;
}

class OtaUpgradeProgress {
  String? iotId;
  String? moduleName;
  String? currentVersion;
  String? firmwareVersion;
  int? step;
  String? details;
  String? otaType;
  int? needConfirm;
  String? status;
  String? desc;
}

@HostApi()
abstract class HostAliLink {
  ///一键配网
  void startAddDeviceByBroadcast(String productKey, String productId);

  /// 热点配网
  void startAddDeviceBySoftAP(String productKey, String productId);

  ///蓝牙配网
  void startAddDeviceByBLE(String productKey, String productId);

  ///设置wifi账号密码
  void toggleProvision(String ssid, String password, int timeout);

  ///成功就可以获取token
  void getDeviceToken(String deviceName, String productKey, int timeout, int interval);

  /// 停止配网
  void stopAddDevice();

  ///扫描和停止扫描
  void startDiscovery();

  void stopDiscovery();

  ///自有账号登录成功，需要调用以下方法完成认证。
  void authCodeLogin(String authCode);

  //配网完成，获取到token，查询iotId
  void getIotId(String token);


  ///获取设备当前可用于升级的固件信息
  @async
  OtaNewVersionInfo? checkOtaUpgradeInfo(String iotId);

  ///开始OTA升级，返回成功或者失败 https://help.aliyun.com/document_detail/188284.html
  @async
  int? startOta(String iotId);

  ///获取ota升级进度
  @async
  OtaUpgradeProgress? getOtaProgress(String iotId);
}

@FlutterApi()
abstract class FlutterAliLink {
  /// 1、参数检测回调
  void onPreCheck(int result, DCErrorCode? dcErrorCode);

  /// 2、配网准备阶段，传入Wi-Fi信息
  // 零配和智能路由器配网不会走到该流程。
  // prepareType = 1提示用户输入账号密码
  // prepareType = 2提示用户手动开启指定热点 aha 12345678
  // 执行完上述操作之后，调用toggleProvision接口继续执行配网流程
  void onProvisionPrepare(int prepareType);

  /// 3、配网中
  void onProvisioning();

  /// 4、状态变化
  void onProvisionStatus(int code, String msg);

  /// 5、配网结果，成功的话，要调用查询token，然后再绑定设备
  void onProvisionedResult(int success, DeviceInfo? deviceInfo, DCErrorCode? dcErrorCode);

  ///扫描到设备
  void onDeviceFound(int type, String? description, List<DeviceInfo>? deviceInfos);

  ///获取token成功
  void getDeviceTokenOnFail(DCErrorCode dcErrorCode);

  ///获取token失败
  void getDeviceTokenOnSuccess(GetTokenResult getTokenResult);

  ///自有账号登录成功，完成认证结果
  void onAuthCodeLoginSuccess();

  void onAuthCodeLoginFailed(int code, String msg);

  void onGetIotIdResult(int result, String? iotId);
}
